// The Vue build version to load with the `import` command
import "babel-polyfill"
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/index'
import axios from 'axios'
import fastclick from 'fastclick'
import VueLazyload from 'vue-lazyload'
import element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import moment from 'moment'
import MetaInfo from 'vue-meta-info'

import Vant from 'vant';
import 'vant/lib/index.css';


import 'style/index.styl'
import {getToken} from 'plus/auth'

fastclick.attach(document.body)
Vue.use(MetaInfo)
Vue.use(VueLazyload, {
  // loading: require('img/default.png')
})
Vue.use(element)
Vue.use(Vant)
Vue.use(VueAwesomeSwiper, /* { default global options } */ )
Vue.config.productionTip = false

Vue.prototype.getLoading = function (text) {
  return this.$loading({
    body: true,
    lock: true,
    text: text || '努力加载中',
    background: 'rgba(0,0,0,0.3)'
  })
}
Vue.prototype.$moment = moment;
/*master库*/
// axios.defaults.baseURL = 'https://campus.goktech.cn/api'
// axios.defaults.baseURL = 'https://campus.yunmansk.com/api'
axios.defaults.baseURL = 'https://test.goktech.cn/api'
// axios.defaults.baseURL = 'http://192.168.2.11:8081'
// axios.defaults.baseURL = '/requist'


// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});

var _hmt = window._hmt || []
/* 使用钩子函数对路由进行权限跳转 */
router.beforeEach((to, from, next) => {
  const REG = /H5Login|H5classList|H5selectDate|H5fastSelect|H5submitSuccess|H5process/i
  const res =  REG.test(to.name);
  if(res && !to.meta.isPhone){
    next(to.name + ' ')
  }
  if (getToken()) {
    next()
  } else {
    if (to.path !== '/personal' && to.path !== '/classList') {
      next()
    } else {
      next('/home')
    }
  }

  router.afterEach((to, from, next) => {
    setTimeout(() => {
      var _hmt = _hmt || [];
      (function () {
        //每次执行前，先移除上次插入的代码
        document.getElementById('baidu_tj') && document.getElementById('baidu_tj').remove();
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?9533b73048cfbe84254e7c8511293b44";//测试
        // hm.src = "https://hm.baidu.com/hm.js?e14eb4f6a76274cef86d25c681494505"; //预发布
        // hm.src = "https://hm.baidu.com/hm.js?7fc7c90fa049e44d475af831a7ac2ed3";//正式
        hm.id = "baidu_tj"
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    }, 0);
  })

  //返回首页时不刷新页面
  const toDepth = to.path.split('/')[1]
  // const fromDepth = from.path.split('/').length
  if (toDepth == '') {
    from.meta.keepAlive = false
    to.meta.keepAlive = true
  }
  if (to.path) {
    _hmt.push(['_trackPageview', '/#' + to.fullPath]);
  }
  next();
})



/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
